using UnityEngine;

public class Inventory : MonoBehaviour
{
    [field: SerializeField] private SerializableDictionary <Resource, int> Resources { get; set;}
    //<summary>
    // 查找并返回字典中某个资源的数量
    ///</summary>
    //<param name="type">要检查的资源类型</param>
    //<returns>如果有资源则返回其数量，否则返回0</returns>
    
    public int GetResourceCount(Resource type)
    {
        if (Resources.TryGetValue(type, out int currentCount))
            return currentCount;
        else
            return 0;
    }

    /// <summary>
    /// 向字典中添加资源
    /// </summary>
    /// <param name="type">要添加的资源类型</param>
    /// <param name="count">要添加的数量</param>
    /// <returns>成功添加的数量</returns>
    public int AddResources(Resource type, int count)
    {
        if (Resources.TryGetValue(type, out int currentCount))
        {
            return Resources[type] += count;
        }
        else
        {
            Resources.Add(type, count);
            return count;
        }
    }
}
